<template>
	<view class="pageItem">
		<view class="timeTool">
			<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
				<view class="uni-input">统计日期：{{date}}</view>
			</picker>
		</view>
		<view class="mainItem">
			<view class="boxCard" v-for="(item,index) in list" :key="'g_'+index">
				<view class="goods">
					<image class="g_img" :src="item.image" mode="widthFix"></image>
					<view class="g_con">
						<view class="g_txt1">{{item.name}}</view>
						<view class="g_txt2">日销量：<label class="g_num">{{item.day}}</label></view>
						<view class="g_txt2">月销量：<label class="g_num">{{item.month}}</label></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				date: currentDate,
				list:[]
			};
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		onReady(){
			this.getListFun();
		},
		methods:{
			bindDateChange: function(e) {
				if(this.date == e.detail.value){
					return
				}
				this.date = e.detail.value;
				//选择完直接触发
				this.getListFun();
			},
			getListFun(){   //请求列表函数
				let nowDate = this.date;
				let nowMonth = this.date.substr(0,7);
				let me = this;
				me.Net._get('goodsTj',{day:nowDate,month:nowMonth},(res)=>{
					if(res.code ==1){
						me.list = res.data;
					}
				});
				console.log(nowDate,nowMonth)
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
	
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			}
		}
	}
</script>

<style lang="scss">
.pageItem{
	width: 100%;
	min-height: 50vh;
	position: relative;
	z-index: 9;
	.timeTool{
		position: fixed;
		z-index: 10;
		top: 20vh;
		right: 0;
		background: rgba(0, 0, 0, .4);
		padding: 15rpx 30rpx 15rpx 20rpx;
		color: #fff;
		border-radius: 10rpx 0 0 10rpx;
	}
	.mainItem{
		width: 100%;
		padding: 0 30rpx 40rpx;
		.boxCard{
			margin-top: 20rpx;
		}
		.boxCard{
			width: 100%;
			padding: 30rpx;
			background: #fff;
			display: inline-block;
			border-radius: 15rpx;
			.goods{
				width: 100%;
				padding:0;
				display: flex;
				.g_img{
					width: 20vw;
					border-radius: 15rpx;
				}
				.g_con{
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					padding-left: 20rpx;
					.g_txt1{
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						font-size: 30rpx;
						color: #333;
					}
					.g_txt2{
						width: 100%;
						font-size: 30rpx;
						color: #ff0000;
						font-weight: bold;
						padding-top: 10rpx;
						.g_num{
							font-size: 35rpx;
						}
					}
				}
			}
		}
	}
}
</style>
